// @ts-nocheck

var NodeSet = require("./NodeSet")
/**
 *
 * @param {HTMLCanvasElement} CanvasDom
 * @param {*} drawAction
 */
function canvasMv(CanvasDom, nodeArr, drawAction) {
	var select_i;
  CanvasDom.onmousedown = function (e) {
		var ePoint = {
			x: e.offsetX - this.clientWidth / 2,
			y: this.clientHeight / 2 - e.offsetY
		}; 
    // document.title = ePoint.x + ":" + ePoint.y + ">>" + time++;
		if ((select_i = NodeSet.getSelect(nodeArr, ePoint)) != null) {
      CanvasDom.stat = "click";
    }
  };

  CanvasDom.onmouseup = function () {
    CanvasDom.stat = "unclick";
	};
	
	CanvasDom.onmousemove = function (e) {
		if (CanvasDom.stat == "click") {
				nodeArr[select_i].y = this.clientHeight / 2 - e.offsetY
				nodeArr[select_i].x = e.offsetX - this.clientWidth / 2
			drawAction && drawAction()
		}
	};
  
}



module.exports = canvasMv